package  
{
	import net.flashpunk.FP;
	import net.flashpunk.graphics.Image;
	import net.flashpunk.World;
	
	/**
	 * ...
	 * @author Donatello
	 */
	public class ThirdScene extends World
	{
		[Embed(source = "img/hallway.png")]	private const IMG_BACK:Class;
		private var imgBack:Image;
		
		[Embed(source = "img/dolar.png")]	private const DOLAR:Class;
		private var dolar1:Image = new Image(DOLAR);
		private var dolar2:Image = new Image(DOLAR);
		private var addD1:Boolean = false;
		private var addD2:Boolean = false;
		
		
		private var player:Player;
		private var girl:Girl;
		private var hallGuy1:HallGuy;
		private var hallGuy2:HallGuy;
		private var texto1:Boolean = false;
		private var texto2:Boolean = false;
		
		private var dolarTime:Number = 0.0;
		
		public function ThirdScene() 
		{
			
			imgBack = new Image(IMG_BACK);
			imgBack.x = 0;
			imgBack.y = 0;
			addGraphic(imgBack);
			
			
			
			
			player = new Player(70, 400);
			girl = new Girl(0, 400);
			
			hallGuy1 = new HallGuy(300, 400);
			add(hallGuy1);
			
			hallGuy2 = new HallGuy(500, 400);
			add(hallGuy2);
					
			add(girl);
			add(player);
		}
		
		
		
		override public function update():void
		{
			dolarTime += FP.elapsed;
			
			if (player.state == "hand")
			{
				girl.stop();
			}
			else
				girl.walk();
			
			if (player.collide("HallGuy", player.x-10, player.y)&& hallGuy1.state!="walking" && hallGuy2.state!="walking")
			{
				FP.world = new ThirdScene();
				removeAll();
			}
			
			if ((hallGuy1.x - player.x) < 60)
			{
				if (player.state == "hand" && hallGuy1.state == "hand")
				{
					if(!texto1)
					{	add(new Dialog("Hola, ¿como te va?", player.x-200, player.y, 2, player.y - 50));
						texto1 = true;
						dolar1.x = player.x+54;
						dolar1.y = player.y + 50;
						addGraphic(dolar1);
						dolarTime = 0.0;
						addD1 = true;
					}
					
					hallGuy1.caminar();
					
				}
			}
			if (dolarTime >= 1 && addD1)
			{
				addD1 = false;
				dolar1.alpha = 0;
			}
			
			
			if ((hallGuy2.x - player.x) < 60)
			{
				if (player.state == "hand" && hallGuy2.state == "hand")
				{
					if(!texto2)
					{	
						add(new Dialog("¿Como estas Gino?", player.x-200, player.y, 2, player.y - 50));
						texto2 = true;
						texto1 = false;
						dolar2.x = player.x+54;
						dolar2.y = player.y + 50;
						addGraphic(dolar2);
						addD2 = true;
						dolarTime = 0.0;
					}
					hallGuy2.caminar();
					
				}
			}	
			
			if (dolarTime >= 1 && addD2)
			{
				addD2 = false;
				dolar2.alpha = 0;
			}
			
			
			if (player.x > 600)
			{
				if(!texto1)
				{	
					add(new Dialog("Siempre que vengo, ustedes dos,JaJa!", player.x-200, player.y, 3, player.y - 50));
					texto1 = true;
				}
			}
			
			if (girl.x > FP.screen.width)
			{
				FP.world = new FourthScene();
				removeAll();
			}
			
				
			super.update();
		}
		
	}

}